home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / epsilon / process.py < prev    next >
Text File  |  2009-03-13  |  2KB  |  44 lines

  1. # -*- test-case-name: epsilon.test.test_process -*-
  2.  
  3. import os, sys, imp, sets
  4.  
  5. from twisted.internet import reactor
  6.  
  7. def spawnProcess(processProtocol, executable, args=(), env={},
  8.                  path=None, uid=None, gid=None, usePTY=0,
  9.                  packages=()):
  10.     """Launch a process with a particular Python environment.
  11.  
  12.     All arguments as to reactor.spawnProcess(), except for the
  13.     addition of an optional packages iterable.  This should be
  14.     of strings naming packages the subprocess is to be able to
  15.     import.
  16.     """
  17.  
  18.     env = env.copy()
  19.  
  20.     pythonpath = []
  21.     for pkg in packages:
  22.         p = os.path.split(imp.find_module(pkg)[1])[0]
  23.         if p.startswith(os.path.join(sys.prefix, 'lib')):
  24.             continue
  25.         pythonpath.append(p)
  26.     pythonpath = list(sets.Set(pythonpath))
  27.     pythonpath.extend(env.get('PYTHONPATH', '').split(os.pathsep))
  28.     env['PYTHONPATH'] = os.pathsep.join(pythonpath)
  29.  
  30.     return reactor.spawnProcess(processProtocol, executable, args,
  31.                                 env, path, uid, gid, usePTY)
  32.  
  33. def spawnPythonProcess(processProtocol, args=(), env={},
  34.                        path=None, uid=None, gid=None, usePTY=0,
  35.                        packages=()):
  36.     """Launch a Python process
  37.  
  38.     All arguments as to spawnProcess(), except the executable
  39.     argument is omitted.
  40.     """
  41.     return spawnProcess(processProtocol, sys.executable,
  42.                         args, env, path, uid, gid, usePTY,
  43.                         packages)
  44.